/*
  作者: 劳兆城
  描述: 创建 Layer 的方法
*/

import LayerTile from 'ol/layer/tile'
import LayerVector from 'ol/layer/vector'
import LayerImage from 'ol/layer/image'
import Overlayer from 'ol/overlay'
import * as Source from './source'
import * as Format from './format'

// 创建 ol.layer.Tile
export const createLayerTile = (options) => new LayerTile(options)

// 创建 ol.layer.Vector
export const createLayerVector = (options) => new LayerVector(options)

// 创建 ol.layer.Image
export const createLayerImage = (options) => new LayerImage(options)

// 创建kml的Layer
export const createLayerKml = (options) => {
  const { url, name } = options

  return createLayerVector({
    source: Source.createSourceVector({
      url: url,
      format: Format.createFormatKml({
        showPointNames: false
      })
    }),
    name
  })
}

// 创建icon的Layer
export const createLayerIcon = (options) => {
  const { layerName, features, zIndex } = options

  return createLayerVector({
    style: function (feature) {
      return feature.get('style')
    },
    source: Source.createSourceVector({
      features
    }),
    name: layerName || '',
    zIndex: zIndex || 1
  })
}

// 创建 ol.Overlay
export const createOverLayer = (options) => new Overlayer({
  offset: [0, -5],
  stopEvent: false,
  ...options
})
